package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
)

type Mysql struct {
	User     string
	Password string
	Host     string
	Port     int
	Dbname   string
}
type AppConfig struct {
	Mysql
}

var Config AppConfig

func Init() {
	var err error

	//1-设置路径
	viper.SetConfigFile("appconfig/dev.yaml")
	//2-读取文件
	err = viper.ReadInConfig()
	if err != nil {
		panic(err)
	}
	//3-映射字段
	err = viper.Unmarshal(&Config)
	if err != nil {
		panic(err)
	}
	fmt.Println("配置文件加载成功:", Config)
}
